SPB Git

Repository Public

page.tsx 7.1 KB 208 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | ACADEMIC RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project          : UQO Éval10 * File             : src/app/estimation/[id]/page.tsx11 * Module           : app12 * Repository       : https://git.spboucher.ai/uqo-eval13 * Project Website  : https://www.uqo-eval.app14 * Created          : 2026-08-0915 * Last Modified    : 2026-08-2816 *17 * =============================================================================18 * SOFTWARE MAINTAINER & AFFILIATION19 * =============================================================================20 *21 * Maintainer       : Simon-Pierre Boucher22 * Position         : Professor of Finance23 * Institution      : Université du Québec en Outaouais (UQO)24 * Department       : Département des sciences administratives25 * Website          : https://spboucher.ai26 * Git              : https://git.spboucher.ai27 *28 * Research Contact : research@spboucher.ai29 * Direct Contact   : simon@spboucher.ai30 * Security/Admin   : admin@spboucher.ai31 *32 * The affiliation is descriptive. It is not an institutional endorsement,33 * a license grant or a determination of ownership.34 *35 * =============================================================================36 * COPYRIGHT, AUTHORSHIP & DATA37 * =============================================================================38 *39 * Copyright (c) the author(s) of this work.40 * Ownership is not asserted by this notice; see the repository records.41 *42 * This header identifies the maintainer of the software. Scientific43 * authorship of any associated paper is stated in the paper itself and44 * is not changed by this notice. Datasets and third-party materials45 * remain the property of their respective owners and licensors.46 *47 * This file is governed by the applicable project license, copyright48 * notices, institutional agreements and relevant law.49 *50 * =============================================================================51 * LICENSE & MAINTENANCE52 * =============================================================================53 *54 * License          : None specified (no license file in this repository)55 * Classification   : Public56 *57 * =============================================================================58 * END OF SP BOUCHER SOURCE HEADER59 * =============================================================================60 */6162// UQO Éval — laboratoire pédagogique d'évaluation immobilière63import type { Metadata } from "next";64import { cache } from "react";65import { notFound } from "next/navigation";66import { estimateByUnitId } from "@/lib/estimator";67import ResultView from "@/components/ResultView";68import {69  EST_YEAR,70  SITE_URL,71  TYPE_LABELS,72  moneyFr,73  slugify,74} from "@/lib/seo";7576export const dynamic = "force-dynamic";7778// Une seule estimation par requête, partagée entre generateMetadata et la page.79const getEstimate = cache((id: string) => estimateByUnitId(id));8081function displayAddress(unit: {82  adresse: string | null;83  specs: { apt: string | null };84  municipalite: string | null;85}): string {86  const apt = unit.specs.apt ? `, app. ${unit.specs.apt}` : "";87  const addr = unit.adresse ?? "Propriété";88  return unit.municipalite ? `${addr}${apt}, ${unit.municipalite}` : `${addr}${apt}`;89}9091export async function generateMetadata({92  params,93}: {94  params: Promise<{ id: string }>;95}): Promise<Metadata> {96  const { id } = await params;97  const decoded = decodeURIComponent(id);98  const data = getEstimate(decoded);99  if (!data?.unit) return { title: "Propriété introuvable" };100  const u = data.unit;101  const r = data.result;102  const typeLabel = TYPE_LABELS[u.typeProp]?.singulier ?? "propriété";103  const annee = u.anneeConstruction ? `, construite en ${u.anneeConstruction}` : "";104  const title = `${displayAddress(u)} — estimation ${EST_YEAR} : ${moneyFr(r.estimate)}`;105  const description = `Valeur estimée de cette ${typeLabel}${annee} : ${moneyFr(106    r.estimate107  )} (fourchette ${moneyFr(r.low)} – ${moneyFr(r.high)}, confiance ${108    r.confidenceLevel109  }). Valeur au rôle, historique 2021-${EST_YEAR} et comparables réels — calcul montré en entier.`;110  return {111    title,112    description,113    alternates: { canonical: `/estimation/${encodeURIComponent(decoded)}` },114    openGraph: { title, description, type: "website" },115  };116}117118/** JSON-LD schema.org : la propriété comme lieu résidentiel + fil d'Ariane. */119function unitJsonLd(data: NonNullable<ReturnType<typeof estimateByUnitId>>) {120  const u = data.unit!;121  const r = data.result;122  const schemaType =123    u.typeProp === "unifamilial" || u.typeProp === "chalet" || u.typeProp === "maison_mobile"124      ? "SingleFamilyResidence"125      : u.typeProp === "plex" || u.typeProp === "condo_ou_multi"126        ? "Residence"127        : "Place";128  const url = `${SITE_URL}/estimation/${encodeURIComponent(u.id)}`;129  const place: Record<string, unknown> = {130    "@type": schemaType,131    "@id": `${url}#place`,132    name: displayAddress(u),133    url,134    address: {135      "@type": "PostalAddress",136      streetAddress: u.adresse ?? undefined,137      addressLocality: u.municipalite ?? undefined,138      addressRegion: "QC",139      addressCountry: "CA",140    },141    geo: { "@type": "GeoCoordinates", latitude: u.lat, longitude: u.lng },142    additionalProperty: [143      {144        "@type": "PropertyValue",145        name: `Estimation UQO Éval ${EST_YEAR}`,146        value: r.estimate,147        unitText: "CAD",148      },149      {150        "@type": "PropertyValue",151        name: "Valeur au rôle d'évaluation",152        value: u.valeurRole ?? undefined,153        unitText: "CAD",154      },155    ],156  };157  if (u.aireEtagesM2) {158    place.floorSize = {159      "@type": "QuantitativeValue",160      value: u.aireEtagesM2,161      unitCode: "MTK",162    };163  }164  if (u.anneeConstruction) place.yearBuilt = u.anneeConstruction;165  const breadcrumb = {166    "@type": "BreadcrumbList",167    itemListElement: [168      { "@type": "ListItem", position: 1, name: "Accueil", item: SITE_URL },169      u.municipalite170        ? {171            "@type": "ListItem",172            position: 2,173            name: u.municipalite,174            item: `${SITE_URL}/municipalite/${slugify(u.municipalite)}`,175          }176        : null,177      {178        "@type": "ListItem",179        position: u.municipalite ? 3 : 2,180        name: u.adresse ?? u.id,181        item: url,182      },183    ].filter(Boolean),184  };185  return { "@context": "https://schema.org", "@graph": [place, breadcrumb] };186}187188export default async function EstimationPage({189  params,190}: {191  params: Promise<{ id: string }>;192}) {193  const { id } = await params;194  const data = getEstimate(decodeURIComponent(id));195  if (!data) notFound();196  return (197    <>198      {data.unit && (199        <script200          type="application/ld+json"201          dangerouslySetInnerHTML={{ __html: JSON.stringify(unitJsonLd(data)) }}202        />203      )}204      <ResultView data={data} />205    </>206  );207}208
Files main
Menu

Theme